package com.zb777.shuzhilingxi.controller;


import com.zb777.shuzhilingxi.Pojo.entity.ChatHistoryDetail;
import com.zb777.shuzhilingxi.Pojo.entity.ChatHistoryList;
import com.zb777.shuzhilingxi.result.Result;
import com.zb777.shuzhilingxi.service.IChatHistoryListService;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author redaiyu
 * @since 2025-07-13
 */
@RestController
@RequestMapping("/history_service")
@Tag(name = "聊天历史管理接口")
public class ChatHistoryListController {

    @Autowired
    private IChatHistoryListService chatHistoryService;

    /**
     * 创建聊天列表
     */
    @PostMapping("/list/create")
    @Schema(name = "创建聊天列表")
    public Result<ChatHistoryList> createChatList(@Validated @RequestBody ChatHistoryList chatHistoryList) {
        ChatHistoryList chatList = chatHistoryService.createChatList(chatHistoryList);
        return Result.success( "创建成功",chatList);
    }

    /**
     * 删除聊天列表
     */
    @DeleteMapping("/list/delete/{listId}")
    @Schema(name ="删除聊天列表")
    public Result<Void> deleteChatList(@PathVariable Integer listId) {
        chatHistoryService.deleteChatList(listId);
        return Result.success("删除成功");
    }

    /**
     * 编辑聊天列表名称
     */
    @PutMapping("/list/edit/{listId}")
    @Schema(name ="编辑聊天列表名称")
    public Result<Void> editChatList(
            @PathVariable Integer listId,
            @Validated @RequestBody ChatHistoryList chatHistoryList
    ) {
        chatHistoryService.editChatList(listId, chatHistoryList);
        return Result.success("更新成功");
    }

    /**
     * 删除聊天详情
     */
    @DeleteMapping("/detail/delete/{detailId}")
    @Schema(name ="删除聊天详情")
    public Result<Void> deleteChatDetail(@PathVariable Integer detailId) {
        chatHistoryService.deleteChatDetail(detailId);
        return Result.success("删除成功");
    }

    /**
     * 编辑聊天详情
     */
    @PutMapping("/detail/edit/{detailId}")
    @Schema(name ="编辑聊天详情")
    public Result<ChatHistoryDetail> editChatDetail(
            @PathVariable Integer detailId,
            @Validated @RequestBody ChatHistoryDetail chatHistoryDetail
    ) {
        ChatHistoryDetail chatDetail = chatHistoryService.editChatDetail(detailId, chatHistoryDetail);
        return Result.success( "更新成功",chatDetail);
    }

    /**
     * 获取当前用户的所有聊天列表
     */
    @GetMapping("/list")
    @Schema(name ="获取聊天列表")
    public Result<List<ChatHistoryList>> getChatLists() {
        List<ChatHistoryList> list = chatHistoryService.getChatLists();
        return Result.success( "获取成功",list);
    }

    /**
     * 获取指定列表的聊天详情
     */
    @GetMapping("/detail/{listId}")
    @Schema(name ="获取聊天详情")
    public Result<List<ChatHistoryDetail>> getChatDetails(@PathVariable Integer listId) {
        List<ChatHistoryDetail> details = chatHistoryService.getChatDetails(listId);
        return Result.success( "获取成功",details);
    }
}
